import sys, os

sys.path.append(os.getcwd())

from selenium.webdriver.common.by import By

from base.base_action import BaseAction

class LoginPage(BaseAction):
    # 登录页面

    # 返回按钮
    login_return_button = By.ID, "com.chebao:id/back"

    # 注册按钮
    login_signin_button = By.ID, "com.chebao:id/regist"

    # 手机号码输入框
    pnum_login = By.ID, "com.chebao:id/login_phone"

    # 密码输入框
    pwd_login = By.ID, "com.chebao:id/psw_phone"

    # 登录按钮
    login_button = By.ID, "com.chebao:id/login_go"

    # 忘记密码
    forgetpwd_login = By.ID, "com.chebao:id/forget"

    # 1208红包  com.chebao:id/tv_register
    login_signin_buttonb = By.ID, "com.chebao:id/tv_register"

    # toast
    login_toast_text = By.XPATH, "//*[contains(@text,'登录')]"

    # 输入的手机号码
    pnum = 18807552421

    # 输入的密码
    pwd = 123456

    def click_login_return_button(self):
        # 点击返回按钮
        self.act_click(self.login_return_button)

    def click_login_signin_button(self):
        # 点击注册按钮
        self.act_click(self.login_signin_button)

    def send_pnum_login(self):
        # 输入手机号码
        self.act_send(self.pnum_login, self.pnum)

    def send_pwd_login(self):
        # 输入密码
        self.act_send(self.pwd_login, self.pwd)

    def click_login_button(self):
        # 点击登录按钮
        self.act_click(self.login_button)

    def click_forgetpwd_login(self):
        # 点击忘记密码
        self.act_click(self.forgetpwd_login)

    def click_login_signin_buttonb(self):
        # 点击“注册立送1208元红包”
        self.act_click(self.login_signin_buttonb)

    def login_toast(self):
        # 获取登录toast
        element = self.find_toast(self.login_toast_text)
        return element.text